package com.aierjun.notepadjun;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by aierJun on 2016/6/18.
 */
public class NewTextActivity extends Activity {
    private DBhelper dBhelper;
    private Button btn_cun;
    private TextView newtext;
    public String KEY_TEXT;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_text_form);
        findView();
    }
    protected void findView(){
        btn_cun= (Button) findViewById(R.id.cun_text);
        newtext= (TextView) findViewById(R.id.new_text);
        btn_cun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KEY_TEXT=newtext.getText().toString();
                sharedPreferences=getSharedPreferences("newName",MODE_PRIVATE);
                editor=sharedPreferences.edit();
                editor.putString("name",KEY_TEXT);
                editor.commit();
                Toast.makeText(NewTextActivity.this,"KEY_TEXT="+KEY_TEXT,Toast.LENGTH_SHORT).show();
                startActivity(new Intent(NewTextActivity.this, HistoryActivity.class));

               /* String text = newtext.getText().toString();
                if (text.length()!=0){
                    dBhelper= new DBhelper(NewTextActivity.this,"Test.db",null,1);
                    SQLiteDatabase db=dBhelper.getWritableDatabase();
                    ContentValues values=new ContentValues();
                    values.put("text",newtext.getText().toString());
                    db.insert("test",null,values);
                    startActivity(new Intent(NewTextActivity.this, HistoryActivity.class));}
                else{
                    newtext.requestFocus();
                }*/
            }
        });
    }
}
